package com.sharedmobility.model;

import java.math.BigDecimal;
import java.sql.Timestamp;

public class Rental {
    private Integer id;
    private Integer vehicleId;
    private Integer userId;
    private Timestamp startTime;
    private Timestamp endTime;
    private String startLocation;  // POINT格式的字符串
    private String endLocation;    // POINT格式的字符串
    private Integer status;        // 0:进行中, 1:已完成, 2:已取消
    private BigDecimal totalAmount;
    private Timestamp createdAt;
    private Timestamp updatedAt;
    
    // 非数据库字段，用于关联显示
    private Vehicle vehicle;       // 关联的车辆信息
    private User user;             // 关联的用户信息
    private BigDecimal estimatedAmount; // 预估金额（用于显示当前进行中的租赁）
    private Long durationMinutes;  // 租赁时长（分钟）

    // Getters and Setters
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getVehicleId() {
        return vehicleId;
    }

    public void setVehicleId(Integer vehicleId) {
        this.vehicleId = vehicleId;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public Timestamp getStartTime() {
        return startTime;
    }

    public void setStartTime(Timestamp startTime) {
        this.startTime = startTime;
    }

    public Timestamp getEndTime() {
        return endTime;
    }

    public void setEndTime(Timestamp endTime) {
        this.endTime = endTime;
    }

    public String getStartLocation() {
        return startLocation;
    }

    public void setStartLocation(String startLocation) {
        this.startLocation = startLocation;
    }

    public String getEndLocation() {
        return endLocation;
    }

    public void setEndLocation(String endLocation) {
        this.endLocation = endLocation;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public BigDecimal getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public Timestamp getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Timestamp createdAt) {
        this.createdAt = createdAt;
    }

    public Timestamp getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Timestamp updatedAt) {
        this.updatedAt = updatedAt;
    }
    
    // 获取关联的车辆信息
    public Vehicle getVehicle() {
        return vehicle;
    }

    // 设置关联的车辆信息
    public void setVehicle(Vehicle vehicle) {
        this.vehicle = vehicle;
    }
    
    // 获取关联的用户信息
    public User getUser() {
        return user;
    }

    // 设置关联的用户信息
    public void setUser(User user) {
        this.user = user;
    }
    
    // 获取预估金额
    public BigDecimal getEstimatedAmount() {
        return estimatedAmount;
    }

    // 设置预估金额
    public void setEstimatedAmount(BigDecimal estimatedAmount) {
        this.estimatedAmount = estimatedAmount;
    }
    
    // 获取租赁时长（分钟）
    public Long getDurationMinutes() {
        // 如果开始时间和结束时间都存在，计算时长
        if (startTime != null && endTime != null) {
            long durationMillis = endTime.getTime() - startTime.getTime();
            return durationMillis / (1000 * 60);
        } 
        // 如果当前租赁进行中，计算至当前时间的时长
        else if (startTime != null) {
            long durationMillis = System.currentTimeMillis() - startTime.getTime();
            return durationMillis / (1000 * 60);
        }
        return null;
    }

    // 设置租赁时长
    public void setDurationMinutes(Long durationMinutes) {
        this.durationMinutes = durationMinutes;
    }
} 